package com.jinxiangyang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jinxiangyang.domain.LiveCourseAccount;
import com.jinxiangyang.mapper.LiveCourseAccountMapper;
import com.jinxiangyang.service.LiveCourseAccountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 直播课程账号表（受保护信息） 服务实现类
 * </p>
 *
 * @author jinxiangyang
 * @since 2023-08-12
 */
@Service
public class LiveCourseAccountServiceImpl extends ServiceImpl<LiveCourseAccountMapper, LiveCourseAccount> implements LiveCourseAccountService {


    @Autowired
    private LiveCourseAccountMapper liveCourseAccountMapper;




    @Override
    public IPage<LiveCourseAccount> getAccountListPageByLike(Long pageNumber, Integer pageSize, LiveCourseAccount account) {
        LambdaQueryWrapper<LiveCourseAccount> lqw = new LambdaQueryWrapper<LiveCourseAccount>();
        lqw.like(Strings.isNotEmpty(account.getZhuboAccount()),LiveCourseAccount::getZhuboAccount,account.getZhuboAccount());
        lqw.like(Strings.isNotEmpty(account.getZhuboKey()),LiveCourseAccount::getZhuboKey,account.getZhuboKey());
        lqw.like(account.getLiveCourseId()!=null &&account.getLiveCourseId()!=0,LiveCourseAccount::getLiveCourseId,account.getLiveCourseId());
        IPage page = new Page(pageNumber,pageSize);
        liveCourseAccountMapper.selectPage(page,lqw);
        return page;
    }


    @Override
    public boolean deleteLiveCourseAccountById(Integer id) {
        return liveCourseAccountMapper.deleteById(id) > 0;
    }


    @Override
    public boolean insertLiveCourseAccount(LiveCourseAccount liveCourseAccount){
        return liveCourseAccountMapper.insert(liveCourseAccount)>0;
    }

    @Override
    public boolean updateLiveCourseAccountById(LiveCourseAccount liveCourseAccount){
        return  liveCourseAccountMapper.updateById(liveCourseAccount)>0;
    }
}
